package com.candy.candymessage.business.service;

import com.candy.candycommon.core.NoticeMsgAdapter;
import com.candy.candycommon.exception.BusinessException;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Map;

/**
 * @author suYanLong
 * @date 2023年01月31日 16:33
 */
@Component
public class MsgSendFactory implements MsgSendService {

    private static Map<String, NoticeMsgAdapter> map;

    public MsgSendFactory(Map<String, NoticeMsgAdapter> map) {
        this.map = map;
    }

    public static NoticeMsgAdapter getMsgNoticeService(String type) {
        if (CollectionUtils.isEmpty(map) || !map.containsKey(type)) {
            throw new BusinessException("不支持此类型通知");
        }
        return map.get(type);
    }

    public Boolean sendMsgNotice(String type, String msg) {
        NoticeMsgAdapter msgNoticeService = getMsgNoticeService(type);
        return msgNoticeService.sendMsgNotice(msg);
    }

    @Override
    public boolean sendMsgNotice(String msg) {
        return false;
    }

}
